package com.bluetane.examples.unittests;

import com.bluetane.pc.BluetaneEvent;
import com.bluetane.pc.BluetaneEvent.BluetaneEventType;
import com.bluetane.pc.BluetaneListener;
import com.bluetane.pc.BluetaneEventSource;
import com.bluetane.pc.BtRemoteDevice;
import javax.bluetooth.RemoteDevice;

enum EventTests{Df1(BluetaneEventType.DeviceFound,new BtRemoteDevice((RemoteDevice)null)),//message is the BtRemoteDevice found
                Df2(BluetaneEventType.DeviceFound,new BtRemoteDevice((RemoteDevice)null)),
                //Ss1(BluetaneEventType.RemoteRunningStatus,false),
                Sf1(BluetaneEventType.SendableRecieved,"new SendableString('Monkeyland')"),
                Ce1(BluetaneEventType.ConnectionEstablished,"AA00BB11C23D45E67F89");

    BluetaneEventType type;
    Object message;
    boolean completed=false;

     EventTests(BluetaneEventType typ, Object msg){
         type=typ;
         message=msg;
     }

     BluetaneEvent buildEvent(EventTest parent){
         return new BluetaneEvent(parent,type,message);
     }

     boolean testOutput(BluetaneEventType typ, Object msg){
         if((typ==type)&&(msg.equals(message))) completed = true;
         return completed;
     }

     static boolean testAllOutputs(BluetaneEventType typ, Object msg){
         boolean anyPassed=false;
        for(EventTests test : EventTests.values()){
            anyPassed |= test.testOutput(typ, msg);
        }
        return anyPassed;
     }

     static boolean allTestsComplete(){
        for(EventTests test : EventTests.values()){
            if(test.completed==false) return false;
        }
        return true;
     }

}


public class EventTest extends BluetaneEventSource implements BluetaneListener
{
    int i=0;
    public EventTest()
    {
        this.addEventListener(this);
        for(EventTests test : EventTests.values()){
            this.fireEvent(test.buildEvent(this));
        }
    }

    public void handleBluetaneEvent(BluetaneEvent event)
    {
        Object msg=event.getMessage();
        BluetaneEventType typ=event.getType();

        boolean result=EventTests.testAllOutputs(typ, msg);
        
        System.out.println(i++);
        System.out.println("Type:    "+typ);
        System.out.println("Message: "+msg);
        System.out.println("Result: "+result);
        System.out.println();
    }

    public static void main(String[] args)
    {
        EventTest mainEventTest = new EventTest();
        System.out.println("Test pass result: "+EventTests.allTestsComplete());
    }
    
}